package com.huashi.dealer.commonEntity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 商家用户权限表
 * 对应数据库表：yoshop_store_access
 * 
 * @author 系统生成
 * @since 2025-01-27
 */
@Data
@TableName("yoshop_store_access")
@Schema(description = "商家用户权限表")
public class StoreAccess implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键id
     */
    @TableId(value = "access_id", type = IdType.AUTO)
    @Schema(description = "主键id")
    private Long accessId;

    /**
     * 权限名称
     */
    @Schema(description = "权限名称")
    private String name;

    /**
     * 权限url
     */
    @Schema(description = "权限url")
    private String url;

    /**
     * 父级id
     */
    @TableField("parent_id")
    @Schema(description = "父级id")
    private Long parentId;

    /**
     * 排序(数字越小越靠前)
     */
    @Schema(description = "排序(数字越小越靠前)")
    private Integer sort;

    /**
     * 创建时间
     */
    @TableField("create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "创建时间")
    private Long createTime;

    /**
     * 更新时间
     */
    @TableField("update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "更新时间")
    private Long updateTime;

    /**
     * 是否删除
     */
    @TableField("is_delete")
    @TableLogic
    @Schema(description = "是否删除")
    private Integer isDelete;

    /**
     * 检查是否为顶级权限
     */
    public boolean isTopLevel() {
        return parentId == null || parentId == 0;
    }

    /**
     * 检查是否有父级权限
     */
    public boolean hasParent() {
        return parentId != null && parentId > 0;
    }

    /**
     * 检查是否已删除
     */
    public boolean isDeleted() {
        return isDelete != null && isDelete == 1;
    }

    /**
     * 获取排序值，如果为空则返回默认值100
     */
    public int getSortValue() {
        return sort != null ? sort : 100;
    }

    /**
     * 检查权限URL是否有效
     */
    public boolean hasValidUrl() {
        return url != null && !url.trim().isEmpty();
    }
}

